package com.block.datapush.service.filter;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.block.datapush.model.param.FilterHandlerParam;
import com.block.datapush.model.result.FilterHandlerResult;
import com.block.datapush.service.IDataFilterItemService;
import com.block.db.entity.MemberSourceInfo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FilterGjjHandlerService implements IDataFilterItemService {

    @Override
    public FilterHandlerResult handlerFilterLogic(FilterHandlerParam handlerParam, MemberSourceInfo memberSourceInfo) {

        String userValue = memberSourceInfo.getGjj();
        String filterValue = handlerParam.getGjj();

        if (StrUtil.isEmpty(filterValue)){
            return FilterHandlerResult.success();
        }

        List<String> valueList = JSON.parseArray(filterValue, String.class);
        if (CollUtil.isEmpty(valueList) || valueList.contains(userValue)){
            return FilterHandlerResult.success();
        }

        String message = StrUtil.format("【filter】{}【value】{}", filterValue, userValue);
        return FilterHandlerResult.error("gjj_error", message);
    }
}
